package com.glory.wxelectricitypda.fragment;


import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.FrameLayout;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.glory.wxelectricitypda.R;
import com.glory.wxelectricitypda.adapter.UnpackagedAdapter;
import com.glory.wxelectricitypda.bean.BoxLabelReviewBean;
import com.pda.platform.ui.ui_pdaplatform.base.FreeUI_BaseFragment;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_CommonCallback;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_AddViewEntity;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DialogUtils;

import butterknife.BindView;

public class UnpackagedFragment extends FreeUI_BaseFragment {

    @BindView(R.id.llMain)
    FrameLayout llMain;
    @BindView(R.id.unpackagedRecycler)
    RecyclerView unpackagedRecycler;
    @BindView(R.id.emptyList)
    TextView emptyList;

    public UnpackagedAdapter mUnpackagedAdapter;

    public UnpackagedFragment() {
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_unpackaged;
    }

    @Override
    protected void initView() {

        unpackagedRecycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        unpackagedRecycler.setItemAnimator(new DefaultItemAnimator());
        unpackagedRecycler.addItemDecoration(new DividerItemDecoration(getActivity(), 1));
        mUnpackagedAdapter = new UnpackagedAdapter(null);
        mUnpackagedAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        mUnpackagedAdapter.isFirstOnly(true);
        unpackagedRecycler.setAdapter(mUnpackagedAdapter);

    }

    @Override
    protected void initData() {

        emptyList.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                FreeApi_DialogUtils.getConfirmAndCancelDialog(getActivity(), "是否确认清空列表?", new FreeUI_CommonCallback() {
                    @Override
                    public void onSuccess() {

                        mUnpackagedAdapter.setNewData(null);
                    }
                }, () -> {}).show(getFragmentManager(),"DELETE_DIALOG");
            }
        });
    }

    public void addData(BoxLabelReviewBean.XPACKAGEDETAILDTO packBean){
        mUnpackagedAdapter.addData(packBean);
    }

    @Override
    protected FreeUI_AddViewEntity getBaseEntity() {
        return null;
    }
}